<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <link href="${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/layer/skin/layer.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/css/bootstrap.min.css"
          rel="stylesheet">
          <link href="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/css/select2.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/font-awesome-4.3.0/css/font-awesome.min.css"
          rel="stylesheet">
          <link rel="stylesheet" href="${pageContext.request.contextPath}/static/plugins/jquery.time/jquery.timepicker.min.css">
    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/layer/layer.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/js/select2.min.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugins/My97DatePicker/WdatePicker.js"
        type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/static/plugins/jquery.time/jquery.timepicker.min.js"
        type="text/javascript"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/global.js"></script>
    <style type="text/css">
        .show_seletor {
            border: 1px solid #EEE;
            padding: 3px;
            background: #337ab7;
            line-height: 20px;
            color: #FFF;
            display: inline-block;
            margin-right: 5px;
        }
        .labe{
        	margin-left: 8px;
        }
    </style>
</head>
<body style="overflow-x: hidden">
<div class="col-sm-12">
    <form class="form-horizontal m-t" method="post" id="form"
          action="${pageContext.request.contextPath}/admin/bannerStrategy_off.action">
         <input type="hidden" value="${map.sid}" name="sid">
         <input type="hidden" value="${map.shelvesid}" name="shid">
         <input type="hidden" id="offType" name="offType">
          <a id="sure" onclick="sure()" hidden="true"></a>
        <div class="form-group">
            <label class="col-sm-3 col-sm-3 control-label">资源名称:</label>
            <div class="col-sm-8">
                <input class="form-control" name="name" size="30" value="${map.cName}" disabled="disabled"/>
            </div>
        </div>
            <div class="form-group">
                <label class="col-sm-3 col-sm-3 control-label">资源类型:</label>
                <div class="col-sm-8">
                    <select class="form-control" name="type" id="type" disabled="disabled">
                        <option value="1">图片</option>
                        <option value="2">h5链接</option>
                    </select>
                </div>
            </div>
         <div class="form-group">
            <label class="col-sm-3 col-sm-3 control-label">URL:</label>
            <div class="col-sm-8">
                <input class="form-control" name="cUrl" size="30" value="${map.cUrl}" disabled="disabled"/>
            </div>
        </div>
         <div class="form-group">
            <label class="col-sm-3 col-sm-3 control-label">结算方式:</label>
            <div class="col-sm-8">
                <input class="form-control" name="settlementMethod" value="${map.settlementMethod}" disabled="disabled" size="30"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 col-sm-3 control-label">预计收益:</label>
            <div class="col-sm-8">
                <input class="form-control" name="expectedIncome" value="${map.expectedIncome}" disabled="disabled" size="30"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 col-sm-3 control-label">广告详情:</label>
            <div class="col-sm-8">
                <input class="form-control" name="adDetails" value="${map.adDetails}" disabled="disabled" size="30"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 col-sm-3 control-label">上架者信息:</label>
            <div class="col-sm-8">
                <input class="form-control" size="30" value="操作者：${map.cUser1}；操作时间：${map.cTime1}" disabled="disabled"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 col-sm-3 control-label">分配者信息:</label>
            <div class="col-sm-8">
            	<textarea rows="5" cols="80%" name="distribute" id="distribute" disabled="disabled" >${map.off}</textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 col-sm-3 control-label">已分配范围:</label>
            <div class="col-sm-8">
			<textarea rows="5" cols="80%" name="distributeRange" id="distributeRange" disabled="disabled" >${map.distributeRange}</textarea>
            </div>
        </div>
       <div class="form-group">
            <label class="col-sm-3 col-sm-3 control-label">下架操作:</label>
            <div class="col-sm-8">
                <input class="form-control" size="30" type="button" id="offbutton" value="下架整个资源" style="background-color: #2E8DED;
    color: #fff !important;" onclick="off()"/>
            </div>
        </div>
         <div class="form-group">
            <label class="col-sm-3 col-sm-3 control-label"><i class="require">*</i>广告位置:</label>
            <div class="col-sm-8">
                <div class="col-sm-2 m-t2" style="width: 150px;" id="range1">
                    <input type="checkbox" id="banner1" name="bannerPosition" disabled="disabled" size="30"  value="1"/><label class="labe">首页</label>
                </div>
                <div class="col-sm-2 m-t2" style="width: 150px;" id="range2">
                    <input type="checkbox" id="banner2" name="bannerPosition" disabled="disabled" size="30" value="2"/><label class="labe">生活服务页</label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 col-sm-3 control-label">要下架范围:</label>
            <div class="col-sm-8">
<!--                 <div class="col-sm-2 m-t2" id="range0" > -->
<!--                     <input type="radio" name="range" size="30" value="0" /><label>全局</label> -->
<!--                 </div> -->
                <div class="col-sm-2 m-t2" style="width: 150px;" id="range1">
                    <input type="radio" name="range" size="30"  value="1"/><label>公司下全部小区</label>
                </div>
                <div class="col-sm-2 m-t2" style="width: 150px;" id="range2">
                    <input type="radio" name="range"  size="30" value="2"/><label>单公司下部分小区</label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">要下架公司:</label>
            <div class="col-sm-8">
                <select id="agtCode" name="agtCode" multiple="multiple"  onchange="changeAgtcode()">
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">要下架小区:</label>
            <div class="col-sm-8">
                <select id="communityId" name="communityId" multiple="multiple" disabled="disabled">
                </select>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
	
    $(function () {
    	$("#type").val('${map.TYPE}');
    	if('${map.banner_position}'.indexOf(',1,')>-1){
    		$("#banner1").attr("checked","checked");
       	}
    	if('${map.banner_position}'.indexOf(',2,')>-1){
    		$("#banner2").attr("checked","checked");
       	}
        $("input[name='range'][value=1]").attr("checked", true);
        var agt;
		if('${map.agtCode}'!=''){
			agt = '${map.agtCode}'+'${map.appendAgt}';
		}else{
	        agt = ',${map.appendAgt}';
		}
		refreshAgtCode(agt.substring(1));
        $("#agtCode").select2({
            "placeholder": "请选择公司",
            "width": "100%"
        })
        $("#communityId").select2({
            "placeholder": "请选择社区",
            "width": "100%"
        })
        $('input:radio[name="range"]').change( function(){
        	  var value = $("input[name='range']:checked").val();
//       	  if(value == 0){
//         		$("#agtCode").empty();
//         		$("#agtCode").select2({
//                     "placeholder": "请选择公司",
//                     "width": "100%"
//                 })
//         		$("#communityId").empty();
//         		$("#communityId").select2({
//                     placeholder: "请选择小区",
//                     width: "100%"
//                 })
//         		$("#agtCode").attr("disabled", "true");
//         		$("#communityId").attr("disabled", "true");
//             }else 
                if(value == 1){//公司下全部小区
//             	$("#agtCode").removeAttr("disabled");
      			$("#agtCode").attr("multiple", "multiple");
       			$("#agtCode").empty();
       			refreshAgtCode(agt.substring(1));
      			$("#communityId").attr("disabled", "true");
      			$("#communityId").empty();
      	  		$("#communityId").select2({
      	              placeholder: "请选择小区",
      	              width: "100%"
      	          })
             }else{//单公司下部分小区
              	$("#agtCode").removeAttr("disabled");
              	$("#agtCode").removeAttr("multiple");
              	$("#agtCode").empty();
              	$("#communityId").attr("disabled", "true");
              	refreshAgtCode(agt.substring(1));
             }
      	 });
    });
  function changeAgtcode()
	{
	  var agtCodes = $("#agtCode").val();
	  var range = $("input[name='range']:checked").val();
	  if(range == 2){
		  $("#communityId").removeAttr("disabled");
		  refreshComuId(agtCodes);
	  }
	}
  
	function off(){
		$("#offType").val("all");
		$("#offbutton").attr("style","background-color: #EAEAE3;color: #000 !important;");
		$("#offbutton").val("已选中下架整个资源");
		$("#agtCode").attr("disabled", "true");
		$("#communityId").attr("disabled", "true");
	}
	function refreshAgtCode(agtcodes){
		$.post("${pageContext.request.contextPath}/admin/tagent_list.action", function (data) {
		   	$("#agtCode").empty();
		    $("#agtCode").append("<option value=''>请选择公司</option>");
			selecteds = agtcodes.split(",");
		    for (var i = 0; i < data.length; i++) {
		    	for (var j=0;j<selecteds.length;j++) {
		        	if(data[i].agtCode == selecteds[j]){
		            $("#agtCode").append("<option value='" + data[i].agtCode + "'>" + data[i].agtName + "</option>");
		         }
		        }
		    }
		
		    $("#agtCode").select2({
		        "placeholder": "请选择公司",
		        "width": "100%"
		    })
		}, "json");
	}
	function refreshComuId(agtCodes,communityIds){
		var arragtAll='';//社区全部上架的公司
		var agtAll = '${map.agtCode}';
		if(agtAll!=''){
			arragtAll = agtAll.substring(1,agtAll.length-1).split(",");
		}
		//社区部分上架的社区
		var arr='';
		var comm = '${map.communityId}';
		if(comm!=''){
			arr = comm.substring(1,comm.length-1).split(",");
		}
		var type = 'normal';
		if(arragtAll.indexOf(agtCodes)>-1){
			type='abnormal';
		}
		$.post("${pageContext.request.contextPath}/admin/tcommunity_listByAgtCodes.action?agtCodes="+agtCodes, function (result) {
		    $("#communityId").empty();
		    $("#communityId").append("<option value=''>请选择小区</option>");
		    if(type=='normal'){
			     for (var i = 0; i < result.length; i++) {
			    	var u;
					if(arr != ''){
		            	u=arr.indexOf(result[i].sid.toString());
		            	if(u != -1){//包含在arr里
			         		$("#communityId").append("<option value='" + result[i].sid + "'>" + result[i].communityName + "</option>");
		                }
					}
		    	}
		    }else{
				for (var i = 0; i < result.length; i++) {
			        $("#communityId").append("<option value='" + result[i].sid + "'>" + result[i].communityName + "</option>");
			     }
			}
		     $("#communityId").select2({
		         placeholder: "请选择小区",
		         width: "100%"
		     })
		}, "json");
	}
</script>
</body>
</html>
